package br.com.wepa.webapps.exporter;

import java.io.File;
import java.util.Map;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2x.AbstractExporter;
import org.hibernate.tool.hbm2x.GenericExporter;
import org.hibernate.tool.hbm2x.pojo.POJOClass;
public class MyExporter extends AbstractExporter {

    public MyExporter() {
    	init();
    }
    
    public MyExporter(Configuration cfg, File outputdir) {
        super(cfg, outputdir);
        init();
    }

    protected void init() {
    	setTemplatePath(new String[]{"exporter/templates"});    	
    }

    protected void setupContext() {
    	/*if(!getProperties().contains("seam_appname")) {
    		getProperties().put("seam_appname", "SeamApplication");	
    	}				
    	if(!getProperties().contains("seam_shortname")) {
    		getProperties().put("seam_shortname", "seamapp");	
    	}*/				
    	
    	super.setupContext();
    }
	protected void exportComponent(Map additionalContext, POJOClass element) {
    	// noop - we dont want components
    }
	
	public String getName() {
		return "hbm2JavaBasicLogic";
	}

	public void doStart() {	
		//configureExporter( "templates/GenericDAO.java.ftl", "{package-name}/if/GenericDAO.java").start();
		//configureExporter( "templates/GenericHibernateDAO.java.ftl", "{package-name}/GenericHibernatebDAO.java").start();		
		configureExporter( "templates/DAO.java.ftl", "{package-name}/{class-name}DAO.java").start();
		configureExporter( "templates/HibernateDAO.java.ftl", "{package-name}/hibernate/{class-name}HibernateDAO.java").start();
		
	}

	private GenericExporter configureExporter(String template, String pattern) {
		MyDAOExporter exporter = new MyDAOExporter(getConfiguration(),getOutputDirectory());
		exporter.setTemplateName(template);
		exporter.setFilePattern(pattern);
		exporter.setTemplatePath(new String[]{"templates"});
		//exporter.getProperties().setProperties((Properties) getProperties().clone());		
		
		return exporter;
	}

}
